package org.example.spring_aop.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Slf4j
@Aspect
@Component
public class TimeRecordAspect {
    @Around("@annotation(org.example.spring_aop.aspect.TimeRecord)")
    public Object timeRecord(ProceedingJoinPoint pjt){
        long start=System.currentTimeMillis();
        Object o= null;
        try {
            o = pjt.proceed();
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }
        long end=System.currentTimeMillis();
        log.info(pjt.getSignature()+"方法执行时间：{}",end-start);
        return o;
    }
}
